<?php

require_once( 'lib/DB.php' );


	$dbInstance = new DB();
	$sql = "select * from citylist";
	$cities = $dbInstance->GetPlan( $sql );
	
	$cityMap = array();
	$provinceMap = array();
	foreach ( $cities as $item )
	{
	    if( $item['parentid'] == 0 ){
	        $provinceMap[$item['name']] = $item['id'];
	    }
	    else{
	        $cityMap[$item['name']] = $item['id'];
	    }
	}

	function getCityByID($locationid)
	{
		global $cityMap, $provinceMap;
		foreach( $cityMap as $key=>$value )
		{
	        if( $value==$locationid )
	        {
	            return $key;
	        }
		}

    	foreach( $provinceMap as $key=>$value )
    	{
    		if( $value==$locationid )
	        {
	            return $key;
	        }
        }
        return '';
    }

	function getCityId( $name )
	{
	    global $cityMap, $provinceMap;
	    foreach( $cityMap as $key=>$value )
	    {
	        if( strpos($name, $key ) === false )
	        {
	            continue;
	        }
	        else
	        {
	            return $value;
	        }
	    }
	
	    foreach( $provinceMap as $key=>$value ){
	        if( strpos( $name, $key ) === false ){
	            continue;
	        }
	        else{
	            return $value;
	        }
	    }
	
	    return 0;
	}
	
$dbInstance->Disconnect();

?>
